package com.csun.cmny.provider.controller.admin;

import com.csun.cmny.core.support.BaseController;
import com.csun.cmny.provider.model.dto.alertConfig.AlertConfigQueryDto;
import com.csun.cmny.provider.model.vo.alertconfig.ConfigureOfflineAlertGroupVO;
import com.csun.cmny.provider.resolver.CmnyMessageSource;
import com.csun.cmny.provider.service.DmcConfigureOfflineAlertGroupService;
import com.csun.cmny.util.wrapper.WrapMapper;
import com.csun.cmny.util.wrapper.Wrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/configureOfflineAlertGroup", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class DmcConfigureOfflineAlertGroupController extends BaseController {

    @Resource
    private DmcConfigureOfflineAlertGroupService dmcConfigureOfflineAlertGroupService;
    @Resource
    private CmnyMessageSource cmnyMessageSource;

    /*
    * 绑定报警信息
    * */
    @PostMapping(value = "/bind/{configureAlertId}/{groupId}")
    public Wrapper bind(@PathVariable Long configureAlertId , @PathVariable Long groupId) {
        if(configureAlertId == null || configureAlertId.equals(0L)){
            return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("alert.config.id.null", null),null);
        }
        if(groupId == null || groupId.equals(0L)){
            return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("group.id.null", null),null);
        }
        Integer result = dmcConfigureOfflineAlertGroupService.bind(configureAlertId,groupId);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /*
    * 开启/关闭报警
    * */
    @PostMapping(value = "/switch/{configureAlertId}/{groupId}")
    public Wrapper changeStatus(@PathVariable Long configureAlertId , @PathVariable Long groupId) {
        if(configureAlertId == null || configureAlertId.equals(0L)){
            return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("alert.config.id.null", null),null);
        }
        if(groupId == null || groupId.equals(0L)){
            return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("group.id.null", null),null);
        }
        Integer result = dmcConfigureOfflineAlertGroupService.changeStatus(configureAlertId,groupId);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }

    /*
    * 分页查询
    * */
    @PostMapping(value = "/listWithPage")
    public Wrapper listWithPage(@RequestBody AlertConfigQueryDto alertConfigQueryDto) {
        PageInfo<ConfigureOfflineAlertGroupVO> pageInfo = dmcConfigureOfflineAlertGroupService.listWithPage(alertConfigQueryDto);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),pageInfo);
    }

    /*
     * 解绑报警信息
     * */
    @PostMapping(value = "/unbind/{configureAlertId}/{groupId}")
    public Wrapper unbind(@PathVariable Long configureAlertId , @PathVariable Long groupId) {
        if(configureAlertId == null || configureAlertId.equals(0L)){
            return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("alert.config.id.null", null),null);
        }
        if(groupId == null || groupId.equals(0L)){
            return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("group.id.null", null),null);
        }
        Integer result = dmcConfigureOfflineAlertGroupService.unbind(configureAlertId,groupId);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE,cmnyMessageSource.getMessage("operation.success", null),result);
    }
}
